import { createApp } from 'vue';
import App from './App.vue';
import { VueRouter } from '@/util/router';
import ElementPlus from 'element-plus';
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';
import 'element-plus/dist/index.css';
import '@/assets/style/common.less';
import store from '@/store';
import useRouterStackStore from '@/store/routerStack';
import http from '@/util/http';

const app = createApp(App);
app.use(VueRouter);
app.use(ElementPlus, {
  locale: zhCn
});
app.use(store);
app.mount('#app')
  .$nextTick(() => postMessage({ payload: 'removeLoading' }, '*'));

//路由变化的时候修改页面标题
const routerStack = useRouterStackStore();
VueRouter.beforeEach((to, from, next) => {
  if (to.meta && to.meta.title) {
    document.title = to.meta.title;
  } else {
    document.title = '\u200E';
  }

  routerStack.setData({
    stack: [
      {
        name: to.meta.title,
        url: to.path
      }
    ]
  });

  if (to.path === from.path && to.path !== '/') {
    location.reload();
  } else {
    next();
  }
});
